<?php
namespace Shakemobile\Controller;
use Think\Controller;
class IndexController extends ExtendController {
	public function index(){
		$USR = M("Friends");
		$score = $USR->where(Array("sid"=>$this->sid,"mixed_nick"=>$this->mixednick))->getField("score");
		$this->assign("score",$score);
		$this->display();
	}
	public function shake(){
		$CFG = M("ShopCfg");
		$cfg = current($CFG->where(Array("sid"=>$this->sid))->getField("id,start_time,end_time"));
		$LOTT = D("Lottery");
		$LOTT->shopcfg = $cfg;
		$sta = $LOTT->check_event();
		if(!$sta["status"]){
			$this->ajaxReturn($sta);
			die();
		}
		$GFT = M("EventsGifts");
		$gifts = $GFT->where(Array("sid"=>$this->sid))->getField("id,name,pic_url,type,level,num_iids,probability,quantity");
		$LOTT->gifts = $gifts;
		
		$USR = M("Friends");
		$user = $USR->where(Array("sid"=>$this->sid,"mixed_nick"=>$this->mixednick))->getField("id,score");
		$LOTT->score = current($user);
		$LOTT->eid = $cfg["id"];
		$LOTT->sid = $this->sid;
		$LOTT->shop_uid = key($user);
		$LOTT->event_uid = key($user);
		
		$re = $LOTT->do_lott();
		$this->ajaxReturn($re);
	}
}